package basic

import (
	"gitee.com/Luna-CY/Golang-Project-Template/entry/http/response"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/context/contextutil"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/errors"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/i18n"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/util/pointer"
	"github.com/gin-gonic/gin"
)

type GetVerifyCaptchaResponse struct {
	Type   string `json:"type" validate:"required" enums:"click"` // 验证码类型，枚举值: click - 点击验证码
	Key    string `json:"key" validate:"required"`                // 验证码的key
	Thumb  string `json:"thumb" validate:"required"`              // 验证码缩略图，base64格式
	Master string `json:"master" validate:"required"`             // 验证码主体图，base64格式
}

// GetVerifyCaptcha 获取验证码
// @tags basic
// @summary 获取验证码
// @success 200 {object} response.Response{data=GetVerifyCaptchaResponse{}} "成功或失败，点击查看响应结构。可切换成功或失败返回对象"
// @router /basic/get-verify-captcha [get]
func (cls *Basic) GetVerifyCaptcha(c *gin.Context) (response.Code, any, errors.I18nError) {
	var ctx = contextutil.NewContextWithGin(c)

	key, thumb, master, err := cls.captcha.GenerateClickCaptcha(ctx)
	if nil != err {
		return response.ServerInternalError, nil, errors.NewI18n(i18n.CommonIdServerInternalError, err.Relation(errors.ErrorServerInternalError("SHGEHB_IC.B_IC.GVC_HA.282104", "获取验证码失败")))
	}

	var res = pointer.Default(GetVerifyCaptchaResponse{
		Type:   "click",
		Key:    key,
		Thumb:  thumb,
		Master: master,
	})

	return response.Ok, res, nil
}
